/**
 * 
 */
package com.worksmap.core.action.system;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.worksmap.core.action.BaseController;
import com.worksmap.core.entity.User;
import com.worksmap.core.service.UserService;

/**
 * @author jack
 * 2013.9.17
 */
@Controller
@RequestMapping("/system/help")
public class SystemHelpController extends BaseController {
	
	@Autowired
	UserService userService;
	
	@RequestMapping(value = "list", method = RequestMethod.GET)
	public String getUserList(HttpServletRequest request, HttpServletResponse response){
		request.setAttribute("userList", userService.getUserList());
		return "system/img_list";
	}
	
	@RequestMapping(value = "register", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, String> register(User user, HttpServletRequest request, HttpServletResponse response){
		logger.info("注册信息：" + user.getUserName() + " 密码:" + user.getPassWord());
		boolean saveFlag = false;
		Map<String, String> map = new HashMap<String, String>(1);   
		try {
			saveFlag = userService.userRegister(user);
		} catch (Exception e) {
			logger.error("用户注册失败！" + e);
			map.put("status", "failed");   
			map.put("message", e.toString());   
			return map;
		}
		if(saveFlag){
			map.put("status", "success");   
			map.put("message", "用户注册成功");   
		}else{
			map.put("status", "failed");   
			map.put("message", "用户注册失败");   
		}
	    return map;
	}
}
